// 完美运动框架

// 取非行间样式
function getStyle(obj, name) {
    if (obj.currentStyle) {
        return obj.currentStyle[name];
    } else {
        return getComputedStyle(obj, null)[name];
    }
};

function startMove(obj, json, fnEnd) {
    clearInterval(obj.timer);

    obj.timer = setInterval(function() {
        // 假设为所有的属性都到了目标点，所以设为true
        var bStop = true;

        for (var attr in json) {
            var cur = 0;
            if (attr == 'opacity') {
                cur = Math.round(parseFloat(getStyle(obj, attr)) * 100);
            } else {
                cur = parseInt(getStyle(obj, attr));
            }

            var speed = (json[attr] - cur) / 6;
            speed = speed > 0 ? Math.ceil(speed) : Math.floor(speed);
            // var speed = -315;


            // 做一个判断，如果 cur!=json[attr]，表示还有属性没到目标点，所以将 bStop 设为 false
            if (cur != json[attr]) bStop = false;

            if (attr == 'opacity') {
                obj.style.fliter = 'alpha(opacity=' + (cur + speed) + ')';
                obj.style.opacity = (cur + speed) / 100;
            } else {
                obj.style[attr] = cur + speed + 'px';
            }

        }

        // 循环外再做一个判断，如果 bStop 为 true，则关闭定时器，执行 fnEnd参数
        if (bStop) {
            clearInterval(obj.timer);

            if (fnEnd) fnEnd();
        }

    }, 30);
};